import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Observable} from 'rxjs';
import {Router} from '@angular/router';

export class TokenInterceptor implements HttpInterceptor {


  private ignoreToken: string[] = [];

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    let clonedReq = req.clone();
    const token = window.localStorage.getItem('token');
    if (token != null) {
      console.log(token);
      const headers = req.headers.set('token', window.localStorage.getItem('token'));
      if (window.localStorage.getItem('token') != null) {
        clonedReq = req.clone({
          headers
        });
      }
    }
    return next.handle(clonedReq);
  }

}
